from playwright.sync_api import sync_playwright
from playwright.async_api import async_playwright

def run(keyword):
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        page.goto("https://www.baidu.com")
        page.fill('input[name="wd"]', keyword)
        page.click('input[type="submit"]')

        page.wait_for_timeout(2000)

        browser.close()
        return 'success'

async def browser_search(query: str):
    async with async_playwright() as p:  # 使用异步上下文管理器
        browser = await p.chromium.launch()  # 异步启动浏览器
        page = await browser.new_page()  # 异步创建页面
        
        try:
            await page.goto('https://www.baidu.com')  # 异步导航
            await page.fill('input[name="q"]', query)  # 异步填充搜索框
            await page.press('input[name="q"]', 'Enter')  # 异步按回车
            await page.wait_for_load_state('networkidle')  # 等待加载完成
            
            content = await page.content()  # 异步获取内容
            return content
            
        finally:
            await browser.close()  # 异步关闭浏览器


if __name__ == '__main__':
    run('日历')